/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/framework/commons/json/serializer/JSONLibDataFormatSerializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: JSONLibDataFormatSerializer.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.json.serializer;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Date;

import com.elancom.framework.commons.json.JSONObject;

public class JSONLibDataFormatSerializer implements ObjectSerializer {

	public JSONLibDataFormatSerializer() {
	}

	@Override
	@SuppressWarnings("deprecation")
	public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
		if (object == null) {
			serializer.getWriter().writeNull();
			return;
		}

		final Date date = (Date) object;

		final JSONObject json = new JSONObject();
		json.put("date", date.getDate());
		json.put("day", date.getDay());
		json.put("hours", date.getHours());
		json.put("minutes", date.getMinutes());
		json.put("month", date.getMonth());
		json.put("seconds", date.getSeconds());
		json.put("time", date.getTime());
		json.put("timezoneOffset", date.getTimezoneOffset());
		json.put("year", date.getYear());

		serializer.write(json);
	}
}
